home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / gcc-2.95.3-3 / info / gcc.info-20 < prev    next >
Encoding:
GNU Info File  |  2001-07-15  |  50.0 KB  |  1,169 lines

  1. This is Info file gcc.info, produced by Makeinfo version 1.68 from the
  2. input file ./gcc.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * gcc: (gcc).                  The GNU Compiler Collection.
  7. END-INFO-DIR-ENTRY
  8.    This file documents the use and the internals of the GNU compiler.
  9.  
  10.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  11. Boston, MA 02111-1307 USA
  12.  
  13.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  14. 1999, 2000 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the sections entitled "GNU General Public License" and "Funding
  23. for Free Software" are included exactly as in the original, and
  24. provided that the entire resulting derived work is distributed under
  25. the terms of a permission notice identical to this one.
  26.  
  27.    Permission is granted to copy and distribute translations of this
  28. manual into another language, under the above conditions for modified
  29. versions, except that the sections entitled "GNU General Public
  30. License" and "Funding for Free Software", and this permission notice,
  31. may be included in translations approved by the Free Software Foundation
  32. instead of in the original English.
  33.  
  34. 
  35. File: gcc.info,  Node: Dependent Patterns,  Next: Jump Patterns,  Prev: Pattern Ordering,  Up: Machine Desc
  36.  
  37. Interdependence of Patterns
  38. ===========================
  39.  
  40.    Every machine description must have a named pattern for each of the
  41. conditional branch names `bCOND'.  The recognition template must always
  42. have the form
  43.  
  44.      (set (pc)
  45.           (if_then_else (COND (cc0) (const_int 0))
  46.                         (label_ref (match_operand 0 "" ""))
  47.                         (pc)))
  48.  
  49. In addition, every machine description must have an anonymous pattern
  50. for each of the possible reverse-conditional branches.  Their templates
  51. look like
  52.  
  53.      (set (pc)
  54.           (if_then_else (COND (cc0) (const_int 0))
  55.                         (pc)
  56.                         (label_ref (match_operand 0 "" ""))))
  57.  
  58. They are necessary because jump optimization can turn direct-conditional
  59. branches into reverse-conditional branches.
  60.  
  61.    It is often convenient to use the `match_operator' construct to
  62. reduce the number of patterns that must be specified for branches.  For
  63. example,
  64.  
  65.      (define_insn ""
  66.        [(set (pc)
  67.              (if_then_else (match_operator 0 "comparison_operator"
  68.                                            [(cc0) (const_int 0)])
  69.                            (pc)
  70.                            (label_ref (match_operand 1 "" ""))))]
  71.        "CONDITION"
  72.        "...")
  73.  
  74.    In some cases machines support instructions identical except for the
  75. machine mode of one or more operands.  For example, there may be
  76. "sign-extend halfword" and "sign-extend byte" instructions whose
  77. patterns are
  78.  
  79.      (set (match_operand:SI 0 ...)
  80.           (extend:SI (match_operand:HI 1 ...)))
  81.      
  82.      (set (match_operand:SI 0 ...)
  83.           (extend:SI (match_operand:QI 1 ...)))
  84.  
  85. Constant integers do not specify a machine mode, so an instruction to
  86. extend a constant value could match either pattern.  The pattern it
  87. actually will match is the one that appears first in the file.  For
  88. correct results, this must be the one for the widest possible mode
  89. (`HImode', here).  If the pattern matches the `QImode' instruction, the
  90. results will be incorrect if the constant value does not actually fit
  91. that mode.
  92.  
  93.    Such instructions to extend constants are rarely generated because
  94. they are optimized away, but they do occasionally happen in nonoptimized
  95. compilations.
  96.  
  97.    If a constraint in a pattern allows a constant, the reload pass may
  98. replace a register with a constant permitted by the constraint in some
  99. cases.  Similarly for memory references.  Because of this substitution,
  100. you should not provide separate patterns for increment and decrement
  101. instructions.  Instead, they should be generated from the same pattern
  102. that supports register-register add insns by examining the operands and
  103. generating the appropriate machine instruction.
  104.  
  105. 
  106. File: gcc.info,  Node: Jump Patterns,  Next: Insn Canonicalizations,  Prev: Dependent Patterns,  Up: Machine Desc
  107.  
  108. Defining Jump Instruction Patterns
  109. ==================================
  110.  
  111.    For most machines, GNU CC assumes that the machine has a condition
  112. code.  A comparison insn sets the condition code, recording the results
  113. of both signed and unsigned comparison of the given operands.  A
  114. separate branch insn tests the condition code and branches or not
  115. according its value.  The branch insns come in distinct signed and
  116. unsigned flavors.  Many common machines, such as the Vax, the 68000 and
  117. the 32000, work this way.
  118.  
  119.    Some machines have distinct signed and unsigned compare
  120. instructions, and only one set of conditional branch instructions.  The
  121. easiest way to handle these machines is to treat them just like the
  122. others until the final stage where assembly code is written.  At this
  123. time, when outputting code for the compare instruction, peek ahead at
  124. the following branch using `next_cc0_user (insn)'.  (The variable
  125. `insn' refers to the insn being output, in the output-writing code in
  126. an instruction pattern.)  If the RTL says that is an unsigned branch,
  127. output an unsigned compare; otherwise output a signed compare.  When
  128. the branch itself is output, you can treat signed and unsigned branches
  129. identically.
  130.  
  131.    The reason you can do this is that GNU CC always generates a pair of
  132. consecutive RTL insns, possibly separated by `note' insns, one to set
  133. the condition code and one to test it, and keeps the pair inviolate
  134. until the end.
  135.  
  136.    To go with this technique, you must define the machine-description
  137. macro `NOTICE_UPDATE_CC' to do `CC_STATUS_INIT'; in other words, no
  138. compare instruction is superfluous.
  139.  
  140.    Some machines have compare-and-branch instructions and no condition
  141. code.  A similar technique works for them.  When it is time to "output"
  142. a compare instruction, record its operands in two static variables.
  143. When outputting the branch-on-condition-code instruction that follows,
  144. actually output a compare-and-branch instruction that uses the
  145. remembered operands.
  146.  
  147.    It also works to define patterns for compare-and-branch instructions.
  148. In optimizing compilation, the pair of compare and branch instructions
  149. will be combined according to these patterns.  But this does not happen
  150. if optimization is not requested.  So you must use one of the solutions
  151. above in addition to any special patterns you define.
  152.  
  153.    In many RISC machines, most instructions do not affect the condition
  154. code and there may not even be a separate condition code register.  On
  155. these machines, the restriction that the definition and use of the
  156. condition code be adjacent insns is not necessary and can prevent
  157. important optimizations.  For example, on the IBM RS/6000, there is a
  158. delay for taken branches unless the condition code register is set three
  159. instructions earlier than the conditional branch.  The instruction
  160. scheduler cannot perform this optimization if it is not permitted to
  161. separate the definition and use of the condition code register.
  162.  
  163.    On these machines, do not use `(cc0)', but instead use a register to
  164. represent the condition code.  If there is a specific condition code
  165. register in the machine, use a hard register.  If the condition code or
  166. comparison result can be placed in any general register, or if there are
  167. multiple condition registers, use a pseudo register.
  168.  
  169.    On some machines, the type of branch instruction generated may
  170. depend on the way the condition code was produced; for example, on the
  171. 68k and Sparc, setting the condition code directly from an add or
  172. subtract instruction does not clear the overflow bit the way that a test
  173. instruction does, so a different branch instruction must be used for
  174. some conditional branches.  For machines that use `(cc0)', the set and
  175. use of the condition code must be adjacent (separated only by `note'
  176. insns) allowing flags in `cc_status' to be used.  (*Note Condition
  177. Code::.)  Also, the comparison and branch insns can be located from
  178. each other by using the functions `prev_cc0_setter' and `next_cc0_user'.
  179.  
  180.    However, this is not true on machines that do not use `(cc0)'.  On
  181. those machines, no assumptions can be made about the adjacency of the
  182. compare and branch insns and the above methods cannot be used.  Instead,
  183. we use the machine mode of the condition code register to record
  184. different formats of the condition code register.
  185.  
  186.    Registers used to store the condition code value should have a mode
  187. that is in class `MODE_CC'.  Normally, it will be `CCmode'.  If
  188. additional modes are required (as for the add example mentioned above in
  189. the Sparc), define the macro `EXTRA_CC_MODES' to list the additional
  190. modes required (*note Condition Code::.).  Also define `EXTRA_CC_NAMES'
  191. to list the names of those modes and `SELECT_CC_MODE' to choose a mode
  192. given an operand of a compare.
  193.  
  194.    If it is known during RTL generation that a different mode will be
  195. required (for example, if the machine has separate compare instructions
  196. for signed and unsigned quantities, like most IBM processors), they can
  197. be specified at that time.
  198.  
  199.    If the cases that require different modes would be made by
  200. instruction combination, the macro `SELECT_CC_MODE' determines which
  201. machine mode should be used for the comparison result.  The patterns
  202. should be written using that mode.  To support the case of the add on
  203. the Sparc discussed above, we have the pattern
  204.  
  205.      (define_insn ""
  206.        [(set (reg:CC_NOOV 0)
  207.              (compare:CC_NOOV
  208.                (plus:SI (match_operand:SI 0 "register_operand" "%r")
  209.                         (match_operand:SI 1 "arith_operand" "rI"))
  210.                (const_int 0)))]
  211.        ""
  212.        "...")
  213.  
  214.    The `SELECT_CC_MODE' macro on the Sparc returns `CC_NOOVmode' for
  215. comparisons whose argument is a `plus'.
  216.  
  217. 
  218. File: gcc.info,  Node: Insn Canonicalizations,  Next: Peephole Definitions,  Prev: Jump Patterns,  Up: Machine Desc
  219.  
  220. Canonicalization of Instructions
  221. ================================
  222.  
  223.    There are often cases where multiple RTL expressions could represent
  224. an operation performed by a single machine instruction.  This situation
  225. is most commonly encountered with logical, branch, and
  226. multiply-accumulate instructions.  In such cases, the compiler attempts
  227. to convert these multiple RTL expressions into a single canonical form
  228. to reduce the number of insn patterns required.
  229.  
  230.    In addition to algebraic simplifications, following canonicalizations
  231. are performed:
  232.  
  233.    * For commutative and comparison operators, a constant is always
  234.      made the second operand.  If a machine only supports a constant as
  235.      the second operand, only patterns that match a constant in the
  236.      second operand need be supplied.
  237.  
  238.      For these operators, if only one operand is a `neg', `not',
  239.      `mult', `plus', or `minus' expression, it will be the first
  240.      operand.
  241.  
  242.    * For the `compare' operator, a constant is always the second operand
  243.      on machines where `cc0' is used (*note Jump Patterns::.).  On other
  244.      machines, there are rare cases where the compiler might want to
  245.      construct a `compare' with a constant as the first operand.
  246.      However, these cases are not common enough for it to be worthwhile
  247.      to provide a pattern matching a constant as the first operand
  248.      unless the machine actually has such an instruction.
  249.  
  250.      An operand of `neg', `not', `mult', `plus', or `minus' is made the
  251.      first operand under the same conditions as above.
  252.  
  253.    * `(minus X (const_int N))' is converted to `(plus X (const_int
  254.      -N))'.
  255.  
  256.    * Within address computations (i.e., inside `mem'), a left shift is
  257.      converted into the appropriate multiplication by a power of two.
  258.  
  259.    * De`Morgan's Law is used to move bitwise negation inside a bitwise
  260.      logical-and or logical-or operation.  If this results in only one
  261.      operand being a `not' expression, it will be the first one.
  262.  
  263.      A machine that has an instruction that performs a bitwise
  264.      logical-and of one operand with the bitwise negation of the other
  265.      should specify the pattern for that instruction as
  266.  
  267.           (define_insn ""
  268.             [(set (match_operand:M 0 ...)
  269.                   (and:M (not:M (match_operand:M 1 ...))
  270.                                (match_operand:M 2 ...)))]
  271.             "..."
  272.             "...")
  273.  
  274.      Similarly, a pattern for a "NAND" instruction should be written
  275.  
  276.           (define_insn ""
  277.             [(set (match_operand:M 0 ...)
  278.                   (ior:M (not:M (match_operand:M 1 ...))
  279.                                (not:M (match_operand:M 2 ...))))]
  280.             "..."
  281.             "...")
  282.  
  283.      In both cases, it is not necessary to include patterns for the many
  284.      logically equivalent RTL expressions.
  285.  
  286.    * The only possible RTL expressions involving both bitwise
  287.      exclusive-or and bitwise negation are `(xor:M X Y)' and `(not:M
  288.      (xor:M X Y))'.
  289.  
  290.    * The sum of three items, one of which is a constant, will only
  291.      appear in the form
  292.  
  293.           (plus:M (plus:M X Y) CONSTANT)
  294.  
  295.    * On machines that do not use `cc0', `(compare X (const_int 0))'
  296.      will be converted to X.
  297.  
  298.    * Equality comparisons of a group of bits (usually a single bit)
  299.      with zero will be written using `zero_extract' rather than the
  300.      equivalent `and' or `sign_extract' operations.
  301.  
  302. 
  303. File: gcc.info,  Node: Peephole Definitions,  Next: Expander Definitions,  Prev: Insn Canonicalizations,  Up: Machine Desc
  304.  
  305. Machine-Specific Peephole Optimizers
  306. ====================================
  307.  
  308.    In addition to instruction patterns the `md' file may contain
  309. definitions of machine-specific peephole optimizations.
  310.  
  311.    The combiner does not notice certain peephole optimizations when the
  312. data flow in the program does not suggest that it should try them.  For
  313. example, sometimes two consecutive insns related in purpose can be
  314. combined even though the second one does not appear to use a register
  315. computed in the first one.  A machine-specific peephole optimizer can
  316. detect such opportunities.
  317.  
  318.    A definition looks like this:
  319.  
  320.      (define_peephole
  321.        [INSN-PATTERN-1
  322.         INSN-PATTERN-2
  323.         ...]
  324.        "CONDITION"
  325.        "TEMPLATE"
  326.        "OPTIONAL INSN-ATTRIBUTES")
  327.  
  328. The last string operand may be omitted if you are not using any
  329. machine-specific information in this machine description.  If present,
  330. it must obey the same rules as in a `define_insn'.
  331.  
  332.    In this skeleton, INSN-PATTERN-1 and so on are patterns to match
  333. consecutive insns.  The optimization applies to a sequence of insns when
  334. INSN-PATTERN-1 matches the first one, INSN-PATTERN-2 matches the next,
  335. and so on.
  336.  
  337.    Each of the insns matched by a peephole must also match a
  338. `define_insn'.  Peepholes are checked only at the last stage just
  339. before code generation, and only optionally.  Therefore, any insn which
  340. would match a peephole but no `define_insn' will cause a crash in code
  341. generation in an unoptimized compilation, or at various optimization
  342. stages.
  343.  
  344.    The operands of the insns are matched with `match_operands',
  345. `match_operator', and `match_dup', as usual.  What is not usual is that
  346. the operand numbers apply to all the insn patterns in the definition.
  347. So, you can check for identical operands in two insns by using
  348. `match_operand' in one insn and `match_dup' in the other.
  349.  
  350.    The operand constraints used in `match_operand' patterns do not have
  351. any direct effect on the applicability of the peephole, but they will
  352. be validated afterward, so make sure your constraints are general enough
  353. to apply whenever the peephole matches.  If the peephole matches but
  354. the constraints are not satisfied, the compiler will crash.
  355.  
  356.    It is safe to omit constraints in all the operands of the peephole;
  357. or you can write constraints which serve as a double-check on the
  358. criteria previously tested.
  359.  
  360.    Once a sequence of insns matches the patterns, the CONDITION is
  361. checked.  This is a C expression which makes the final decision whether
  362. to perform the optimization (we do so if the expression is nonzero).  If
  363. CONDITION is omitted (in other words, the string is empty) then the
  364. optimization is applied to every sequence of insns that matches the
  365. patterns.
  366.  
  367.    The defined peephole optimizations are applied after register
  368. allocation is complete.  Therefore, the peephole definition can check
  369. which operands have ended up in which kinds of registers, just by
  370. looking at the operands.
  371.  
  372.    The way to refer to the operands in CONDITION is to write
  373. `operands[I]' for operand number I (as matched by `(match_operand I
  374. ...)').  Use the variable `insn' to refer to the last of the insns
  375. being matched; use `prev_active_insn' to find the preceding insns.
  376.  
  377.    When optimizing computations with intermediate results, you can use
  378. CONDITION to match only when the intermediate results are not used
  379. elsewhere.  Use the C expression `dead_or_set_p (INSN, OP)', where INSN
  380. is the insn in which you expect the value to be used for the last time
  381. (from the value of `insn', together with use of `prev_nonnote_insn'),
  382. and OP is the intermediate value (from `operands[I]').
  383.  
  384.    Applying the optimization means replacing the sequence of insns with
  385. one new insn.  The TEMPLATE controls ultimate output of assembler code
  386. for this combined insn.  It works exactly like the template of a
  387. `define_insn'.  Operand numbers in this template are the same ones used
  388. in matching the original sequence of insns.
  389.  
  390.    The result of a defined peephole optimizer does not need to match
  391. any of the insn patterns in the machine description; it does not even
  392. have an opportunity to match them.  The peephole optimizer definition
  393. itself serves as the insn pattern to control how the insn is output.
  394.  
  395.    Defined peephole optimizers are run as assembler code is being
  396. output, so the insns they produce are never combined or rearranged in
  397. any way.
  398.  
  399.    Here is an example, taken from the 68000 machine description:
  400.  
  401.      (define_peephole
  402.        [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
  403.         (set (match_operand:DF 0 "register_operand" "=f")
  404.              (match_operand:DF 1 "register_operand" "ad"))]
  405.        "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
  406.        "*
  407.      {
  408.        rtx xoperands[2];
  409.        xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  410.      #ifdef MOTOROLA
  411.        output_asm_insn (\"move.l %1,(sp)\", xoperands);
  412.        output_asm_insn (\"move.l %1,-(sp)\", operands);
  413.        return \"fmove.d (sp)+,%0\";
  414.      #else
  415.        output_asm_insn (\"movel %1,sp@\", xoperands);
  416.        output_asm_insn (\"movel %1,sp@-\", operands);
  417.        return \"fmoved sp@+,%0\";
  418.      #endif
  419.      }
  420.      ")
  421.  
  422.    The effect of this optimization is to change
  423.  
  424.      jbsr _foobar
  425.      addql #4,sp
  426.      movel d1,sp@-
  427.      movel d0,sp@-
  428.      fmoved sp@+,fp0
  429.  
  430. into
  431.  
  432.      jbsr _foobar
  433.      movel d1,sp@
  434.      movel d0,sp@-
  435.      fmoved sp@+,fp0
  436.  
  437.    INSN-PATTERN-1 and so on look *almost* like the second operand of
  438. `define_insn'.  There is one important difference: the second operand
  439. of `define_insn' consists of one or more RTX's enclosed in square
  440. brackets.  Usually, there is only one: then the same action can be
  441. written as an element of a `define_peephole'.  But when there are
  442. multiple actions in a `define_insn', they are implicitly enclosed in a
  443. `parallel'.  Then you must explicitly write the `parallel', and the
  444. square brackets within it, in the `define_peephole'.  Thus, if an insn
  445. pattern looks like this,
  446.  
  447.      (define_insn "divmodsi4"
  448.        [(set (match_operand:SI 0 "general_operand" "=d")
  449.              (div:SI (match_operand:SI 1 "general_operand" "0")
  450.                      (match_operand:SI 2 "general_operand" "dmsK")))
  451.         (set (match_operand:SI 3 "general_operand" "=d")
  452.              (mod:SI (match_dup 1) (match_dup 2)))]
  453.        "TARGET_68020"
  454.        "divsl%.l %2,%3:%0")
  455.  
  456. then the way to mention this insn in a peephole is as follows:
  457.  
  458.      (define_peephole
  459.        [...
  460.         (parallel
  461.          [(set (match_operand:SI 0 "general_operand" "=d")
  462.                (div:SI (match_operand:SI 1 "general_operand" "0")
  463.                        (match_operand:SI 2 "general_operand" "dmsK")))
  464.           (set (match_operand:SI 3 "general_operand" "=d")
  465.                (mod:SI (match_dup 1) (match_dup 2)))])
  466.         ...]
  467.        ...)
  468.  
  469. 
  470. File: gcc.info,  Node: Expander Definitions,  Next: Insn Splitting,  Prev: Peephole Definitions,  Up: Machine Desc
  471.  
  472. Defining RTL Sequences for Code Generation
  473. ==========================================
  474.  
  475.    On some target machines, some standard pattern names for RTL
  476. generation cannot be handled with single insn, but a sequence of RTL
  477. insns can represent them.  For these target machines, you can write a
  478. `define_expand' to specify how to generate the sequence of RTL.
  479.  
  480.    A `define_expand' is an RTL expression that looks almost like a
  481. `define_insn'; but, unlike the latter, a `define_expand' is used only
  482. for RTL generation and it can produce more than one RTL insn.
  483.  
  484.    A `define_expand' RTX has four operands:
  485.  
  486.    * The name.  Each `define_expand' must have a name, since the only
  487.      use for it is to refer to it by name.
  488.  
  489.    * The RTL template.  This is just like the RTL template for a
  490.      `define_peephole' in that it is a vector of RTL expressions each
  491.      being one insn.
  492.  
  493.    * The condition, a string containing a C expression.  This
  494.      expression is used to express how the availability of this pattern
  495.      depends on subclasses of target machine, selected by command-line
  496.      options when GNU CC is run.  This is just like the condition of a
  497.      `define_insn' that has a standard name.  Therefore, the condition
  498.      (if present) may not depend on the data in the insn being matched,
  499.      but only the target-machine-type flags.  The compiler needs to
  500.      test these conditions during initialization in order to learn
  501.      exactly which named instructions are available in a particular run.
  502.  
  503.    * The preparation statements, a string containing zero or more C
  504.      statements which are to be executed before RTL code is generated
  505.      from the RTL template.
  506.  
  507.      Usually these statements prepare temporary registers for use as
  508.      internal operands in the RTL template, but they can also generate
  509.      RTL insns directly by calling routines such as `emit_insn', etc.
  510.      Any such insns precede the ones that come from the RTL template.
  511.  
  512.    Every RTL insn emitted by a `define_expand' must match some
  513. `define_insn' in the machine description.  Otherwise, the compiler will
  514. crash when trying to generate code for the insn or trying to optimize
  515. it.
  516.  
  517.    The RTL template, in addition to controlling generation of RTL insns,
  518. also describes the operands that need to be specified when this pattern
  519. is used.  In particular, it gives a predicate for each operand.
  520.  
  521.    A true operand, which needs to be specified in order to generate RTL
  522. from the pattern, should be described with a `match_operand' in its
  523. first occurrence in the RTL template.  This enters information on the
  524. operand's predicate into the tables that record such things.  GNU CC
  525. uses the information to preload the operand into a register if that is
  526. required for valid RTL code.  If the operand is referred to more than
  527. once, subsequent references should use `match_dup'.
  528.  
  529.    The RTL template may also refer to internal "operands" which are
  530. temporary registers or labels used only within the sequence made by the
  531. `define_expand'.  Internal operands are substituted into the RTL
  532. template with `match_dup', never with `match_operand'.  The values of
  533. the internal operands are not passed in as arguments by the compiler
  534. when it requests use of this pattern.  Instead, they are computed
  535. within the pattern, in the preparation statements.  These statements
  536. compute the values and store them into the appropriate elements of
  537. `operands' so that `match_dup' can find them.
  538.  
  539.    There are two special macros defined for use in the preparation
  540. statements: `DONE' and `FAIL'.  Use them with a following semicolon, as
  541. a statement.
  542.  
  543. `DONE'
  544.      Use the `DONE' macro to end RTL generation for the pattern.  The
  545.      only RTL insns resulting from the pattern on this occasion will be
  546.      those already emitted by explicit calls to `emit_insn' within the
  547.      preparation statements; the RTL template will not be generated.
  548.  
  549. `FAIL'
  550.      Make the pattern fail on this occasion.  When a pattern fails, it
  551.      means that the pattern was not truly available.  The calling
  552.      routines in the compiler will try other strategies for code
  553.      generation using other patterns.
  554.  
  555.      Failure is currently supported only for binary (addition,
  556.      multiplication, shifting, etc.) and bitfield (`extv', `extzv', and
  557.      `insv') operations.
  558.  
  559.    Here is an example, the definition of left-shift for the SPUR chip:
  560.  
  561.      (define_expand "ashlsi3"
  562.        [(set (match_operand:SI 0 "register_operand" "")
  563.              (ashift:SI
  564.  
  565.                (match_operand:SI 1 "register_operand" "")
  566.                (match_operand:SI 2 "nonmemory_operand" "")))]
  567.        ""
  568.        "
  569.  
  570.      {
  571.        if (GET_CODE (operands[2]) != CONST_INT
  572.            || (unsigned) INTVAL (operands[2]) > 3)
  573.          FAIL;
  574.      }")
  575.  
  576. This example uses `define_expand' so that it can generate an RTL insn
  577. for shifting when the shift-count is in the supported range of 0 to 3
  578. but fail in other cases where machine insns aren't available.  When it
  579. fails, the compiler tries another strategy using different patterns
  580. (such as, a library call).
  581.  
  582.    If the compiler were able to handle nontrivial condition-strings in
  583. patterns with names, then it would be possible to use a `define_insn'
  584. in that case.  Here is another case (zero-extension on the 68000) which
  585. makes more use of the power of `define_expand':
  586.  
  587.      (define_expand "zero_extendhisi2"
  588.        [(set (match_operand:SI 0 "general_operand" "")
  589.              (const_int 0))
  590.         (set (strict_low_part
  591.                (subreg:HI
  592.                  (match_dup 0)
  593.                  0))
  594.              (match_operand:HI 1 "general_operand" ""))]
  595.        ""
  596.        "operands[1] = make_safe_from (operands[1], operands[0]);")
  597.  
  598. Here two RTL insns are generated, one to clear the entire output operand
  599. and the other to copy the input operand into its low half.  This
  600. sequence is incorrect if the input operand refers to [the old value of]
  601. the output operand, so the preparation statement makes sure this isn't
  602. so.  The function `make_safe_from' copies the `operands[1]' into a
  603. temporary register if it refers to `operands[0]'.  It does this by
  604. emitting another RTL insn.
  605.  
  606.    Finally, a third example shows the use of an internal operand.
  607. Zero-extension on the SPUR chip is done by `and'-ing the result against
  608. a halfword mask.  But this mask cannot be represented by a `const_int'
  609. because the constant value is too large to be legitimate on this
  610. machine.  So it must be copied into a register with `force_reg' and
  611. then the register used in the `and'.
  612.  
  613.      (define_expand "zero_extendhisi2"
  614.        [(set (match_operand:SI 0 "register_operand" "")
  615.              (and:SI (subreg:SI
  616.                        (match_operand:HI 1 "register_operand" "")
  617.                        0)
  618.                      (match_dup 2)))]
  619.        ""
  620.        "operands[2]
  621.           = force_reg (SImode, GEN_INT (65535)); ")
  622.  
  623.    *Note:* If the `define_expand' is used to serve a standard binary or
  624. unary arithmetic operation or a bitfield operation, then the last insn
  625. it generates must not be a `code_label', `barrier' or `note'.  It must
  626. be an `insn', `jump_insn' or `call_insn'.  If you don't need a real insn
  627. at the end, emit an insn to copy the result of the operation into
  628. itself.  Such an insn will generate no code, but it can avoid problems
  629. in the compiler.
  630.  
  631. 
  632. File: gcc.info,  Node: Insn Splitting,  Next: Insn Attributes,  Prev: Expander Definitions,  Up: Machine Desc
  633.  
  634. Defining How to Split Instructions
  635. ==================================
  636.  
  637.    There are two cases where you should specify how to split a pattern
  638. into multiple insns.  On machines that have instructions requiring delay
  639. slots (*note Delay Slots::.) or that have instructions whose output is
  640. not available for multiple cycles (*note Function Units::.), the
  641. compiler phases that optimize these cases need to be able to move insns
  642. into one-instruction delay slots.  However, some insns may generate
  643. more than one machine instruction.  These insns cannot be placed into a
  644. delay slot.
  645.  
  646.    Often you can rewrite the single insn as a list of individual insns,
  647. each corresponding to one machine instruction.  The disadvantage of
  648. doing so is that it will cause the compilation to be slower and require
  649. more space.  If the resulting insns are too complex, it may also
  650. suppress some optimizations.  The compiler splits the insn if there is a
  651. reason to believe that it might improve instruction or delay slot
  652. scheduling.
  653.  
  654.    The insn combiner phase also splits putative insns.  If three insns
  655. are merged into one insn with a complex expression that cannot be
  656. matched by some `define_insn' pattern, the combiner phase attempts to
  657. split the complex pattern into two insns that are recognized.  Usually
  658. it can break the complex pattern into two patterns by splitting out some
  659. subexpression.  However, in some other cases, such as performing an
  660. addition of a large constant in two insns on a RISC machine, the way to
  661. split the addition into two insns is machine-dependent.
  662.  
  663.    The `define_split' definition tells the compiler how to split a
  664. complex insn into several simpler insns.  It looks like this:
  665.  
  666.      (define_split
  667.        [INSN-PATTERN]
  668.        "CONDITION"
  669.        [NEW-INSN-PATTERN-1
  670.         NEW-INSN-PATTERN-2
  671.         ...]
  672.        "PREPARATION STATEMENTS")
  673.  
  674.    INSN-PATTERN is a pattern that needs to be split and CONDITION is
  675. the final condition to be tested, as in a `define_insn'.  When an insn
  676. matching INSN-PATTERN and satisfying CONDITION is found, it is replaced
  677. in the insn list with the insns given by NEW-INSN-PATTERN-1,
  678. NEW-INSN-PATTERN-2, etc.
  679.  
  680.    The PREPARATION STATEMENTS are similar to those statements that are
  681. specified for `define_expand' (*note Expander Definitions::.)  and are
  682. executed before the new RTL is generated to prepare for the generated
  683. code or emit some insns whose pattern is not fixed.  Unlike those in
  684. `define_expand', however, these statements must not generate any new
  685. pseudo-registers.  Once reload has completed, they also must not
  686. allocate any space in the stack frame.
  687.  
  688.    Patterns are matched against INSN-PATTERN in two different
  689. circumstances.  If an insn needs to be split for delay slot scheduling
  690. or insn scheduling, the insn is already known to be valid, which means
  691. that it must have been matched by some `define_insn' and, if
  692. `reload_completed' is non-zero, is known to satisfy the constraints of
  693. that `define_insn'.  In that case, the new insn patterns must also be
  694. insns that are matched by some `define_insn' and, if `reload_completed'
  695. is non-zero, must also satisfy the constraints of those definitions.
  696.  
  697.    As an example of this usage of `define_split', consider the following
  698. example from `a29k.md', which splits a `sign_extend' from `HImode' to
  699. `SImode' into a pair of shift insns:
  700.  
  701.      (define_split
  702.        [(set (match_operand:SI 0 "gen_reg_operand" "")
  703.              (sign_extend:SI (match_operand:HI 1 "gen_reg_operand" "")))]
  704.        ""
  705.        [(set (match_dup 0)
  706.              (ashift:SI (match_dup 1)
  707.                         (const_int 16)))
  708.         (set (match_dup 0)
  709.              (ashiftrt:SI (match_dup 0)
  710.                           (const_int 16)))]
  711.        "
  712.      { operands[1] = gen_lowpart (SImode, operands[1]); }")
  713.  
  714.    When the combiner phase tries to split an insn pattern, it is always
  715. the case that the pattern is *not* matched by any `define_insn'.  The
  716. combiner pass first tries to split a single `set' expression and then
  717. the same `set' expression inside a `parallel', but followed by a
  718. `clobber' of a pseudo-reg to use as a scratch register.  In these
  719. cases, the combiner expects exactly two new insn patterns to be
  720. generated.  It will verify that these patterns match some `define_insn'
  721. definitions, so you need not do this test in the `define_split' (of
  722. course, there is no point in writing a `define_split' that will never
  723. produce insns that match).
  724.  
  725.    Here is an example of this use of `define_split', taken from
  726. `rs6000.md':
  727.  
  728.      (define_split
  729.        [(set (match_operand:SI 0 "gen_reg_operand" "")
  730.              (plus:SI (match_operand:SI 1 "gen_reg_operand" "")
  731.                       (match_operand:SI 2 "non_add_cint_operand" "")))]
  732.        ""
  733.        [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
  734.         (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
  735.      "
  736.      {
  737.        int low = INTVAL (operands[2]) & 0xffff;
  738.        int high = (unsigned) INTVAL (operands[2]) >> 16;
  739.      
  740.        if (low & 0x8000)
  741.          high++, low |= 0xffff0000;
  742.      
  743.        operands[3] = GEN_INT (high << 16);
  744.        operands[4] = GEN_INT (low);
  745.      }")
  746.  
  747.    Here the predicate `non_add_cint_operand' matches any `const_int'
  748. that is *not* a valid operand of a single add insn.  The add with the
  749. smaller displacement is written so that it can be substituted into the
  750. address of a subsequent operation.
  751.  
  752.    An example that uses a scratch register, from the same file,
  753. generates an equality comparison of a register and a large constant:
  754.  
  755.      (define_split
  756.        [(set (match_operand:CC 0 "cc_reg_operand" "")
  757.              (compare:CC (match_operand:SI 1 "gen_reg_operand" "")
  758.                          (match_operand:SI 2 "non_short_cint_operand" "")))
  759.         (clobber (match_operand:SI 3 "gen_reg_operand" ""))]
  760.        "find_single_use (operands[0], insn, 0)
  761.         && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
  762.             || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
  763.        [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
  764.         (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
  765.        "
  766.      {
  767.        /* Get the constant we are comparing against, C, and see what it
  768.           looks like sign-extended to 16 bits.  Then see what constant
  769.           could be XOR'ed with C to get the sign-extended value.  */
  770.      
  771.        int c = INTVAL (operands[2]);
  772.        int sextc = (c << 16) >> 16;
  773.        int xorv = c ^ sextc;
  774.      
  775.        operands[4] = GEN_INT (xorv);
  776.        operands[5] = GEN_INT (sextc);
  777.      }")
  778.  
  779.    To avoid confusion, don't write a single `define_split' that accepts
  780. some insns that match some `define_insn' as well as some insns that
  781. don't.  Instead, write two separate `define_split' definitions, one for
  782. the insns that are valid and one for the insns that are not valid.
  783.  
  784. 
  785. File: gcc.info,  Node: Insn Attributes,  Prev: Insn Splitting,  Up: Machine Desc
  786.  
  787. Instruction Attributes
  788. ======================
  789.  
  790.    In addition to describing the instruction supported by the target
  791. machine, the `md' file also defines a group of "attributes" and a set of
  792. values for each.  Every generated insn is assigned a value for each
  793. attribute.  One possible attribute would be the effect that the insn
  794. has on the machine's condition code.  This attribute can then be used
  795. by `NOTICE_UPDATE_CC' to track the condition codes.
  796.  
  797. * Menu:
  798.  
  799. * Defining Attributes:: Specifying attributes and their values.
  800. * Expressions::         Valid expressions for attribute values.
  801. * Tagging Insns::       Assigning attribute values to insns.
  802. * Attr Example::        An example of assigning attributes.
  803. * Insn Lengths::        Computing the length of insns.
  804. * Constant Attributes:: Defining attributes that are constant.
  805. * Delay Slots::         Defining delay slots required for a machine.
  806. * Function Units::      Specifying information for insn scheduling.
  807.  
  808. 
  809. File: gcc.info,  Node: Defining Attributes,  Next: Expressions,  Up: Insn Attributes
  810.  
  811. Defining Attributes and their Values
  812. ------------------------------------
  813.  
  814.    The `define_attr' expression is used to define each attribute
  815. required by the target machine.  It looks like:
  816.  
  817.      (define_attr NAME LIST-OF-VALUES DEFAULT)
  818.  
  819.    NAME is a string specifying the name of the attribute being defined.
  820.  
  821.    LIST-OF-VALUES is either a string that specifies a comma-separated
  822. list of values that can be assigned to the attribute, or a null string
  823. to indicate that the attribute takes numeric values.
  824.  
  825.    DEFAULT is an attribute expression that gives the value of this
  826. attribute for insns that match patterns whose definition does not
  827. include an explicit value for this attribute.  *Note Attr Example::,
  828. for more information on the handling of defaults.  *Note Constant
  829. Attributes::, for information on attributes that do not depend on any
  830. particular insn.
  831.  
  832.    For each defined attribute, a number of definitions are written to
  833. the `insn-attr.h' file.  For cases where an explicit set of values is
  834. specified for an attribute, the following are defined:
  835.  
  836.    * A `#define' is written for the symbol `HAVE_ATTR_NAME'.
  837.  
  838.    * An enumeral class is defined for `attr_NAME' with elements of the
  839.      form `UPPER-NAME_UPPER-VALUE' where the attribute name and value
  840.      are first converted to upper case.
  841.  
  842.    * A function `get_attr_NAME' is defined that is passed an insn and
  843.      returns the attribute value for that insn.
  844.  
  845.    For example, if the following is present in the `md' file:
  846.  
  847.      (define_attr "type" "branch,fp,load,store,arith" ...)
  848.  
  849. the following lines will be written to the file `insn-attr.h'.
  850.  
  851.      #define HAVE_ATTR_type
  852.      enum attr_type {TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
  853.                       TYPE_STORE, TYPE_ARITH};
  854.      extern enum attr_type get_attr_type ();
  855.  
  856.    If the attribute takes numeric values, no `enum' type will be
  857. defined and the function to obtain the attribute's value will return
  858. `int'.
  859.  
  860. 
  861. File: gcc.info,  Node: Expressions,  Next: Tagging Insns,  Prev: Defining Attributes,  Up: Insn Attributes
  862.  
  863. Attribute Expressions
  864. ---------------------
  865.  
  866.    RTL expressions used to define attributes use the codes described
  867. above plus a few specific to attribute definitions, to be discussed
  868. below.  Attribute value expressions must have one of the following
  869. forms:
  870.  
  871. `(const_int I)'
  872.      The integer I specifies the value of a numeric attribute.  I must
  873.      be non-negative.
  874.  
  875.      The value of a numeric attribute can be specified either with a
  876.      `const_int', or as an integer represented as a string in
  877.      `const_string', `eq_attr' (see below), `attr', `symbol_ref',
  878.      simple arithmetic expressions, and `set_attr' overrides on
  879.      specific instructions (*note Tagging Insns::.).
  880.  
  881. `(const_string VALUE)'
  882.      The string VALUE specifies a constant attribute value.  If VALUE
  883.      is specified as `"*"', it means that the default value of the
  884.      attribute is to be used for the insn containing this expression.
  885.      `"*"' obviously cannot be used in the DEFAULT expression of a
  886.      `define_attr'.
  887.  
  888.      If the attribute whose value is being specified is numeric, VALUE
  889.      must be a string containing a non-negative integer (normally
  890.      `const_int' would be used in this case).  Otherwise, it must
  891.      contain one of the valid values for the attribute.
  892.  
  893. `(if_then_else TEST TRUE-VALUE FALSE-VALUE)'
  894.      TEST specifies an attribute test, whose format is defined below.
  895.      The value of this expression is TRUE-VALUE if TEST is true,
  896.      otherwise it is FALSE-VALUE.
  897.  
  898. `(cond [TEST1 VALUE1 ...] DEFAULT)'
  899.      The first operand of this expression is a vector containing an even
  900.      number of expressions and consisting of pairs of TEST and VALUE
  901.      expressions.  The value of the `cond' expression is that of the
  902.      VALUE corresponding to the first true TEST expression.  If none of
  903.      the TEST expressions are true, the value of the `cond' expression
  904.      is that of the DEFAULT expression.
  905.  
  906.    TEST expressions can have one of the following forms:
  907.  
  908. `(const_int I)'
  909.      This test is true if I is non-zero and false otherwise.
  910.  
  911. `(not TEST)'
  912. `(ior TEST1 TEST2)'
  913. `(and TEST1 TEST2)'
  914.      These tests are true if the indicated logical function is true.
  915.  
  916. `(match_operand:M N PRED CONSTRAINTS)'
  917.      This test is true if operand N of the insn whose attribute value
  918.      is being determined has mode M (this part of the test is ignored
  919.      if M is `VOIDmode') and the function specified by the string PRED
  920.      returns a non-zero value when passed operand N and mode M (this
  921.      part of the test is ignored if PRED is the null string).
  922.  
  923.      The CONSTRAINTS operand is ignored and should be the null string.
  924.  
  925. `(le ARITH1 ARITH2)'
  926. `(leu ARITH1 ARITH2)'
  927. `(lt ARITH1 ARITH2)'
  928. `(ltu ARITH1 ARITH2)'
  929. `(gt ARITH1 ARITH2)'
  930. `(gtu ARITH1 ARITH2)'
  931. `(ge ARITH1 ARITH2)'
  932. `(geu ARITH1 ARITH2)'
  933. `(ne ARITH1 ARITH2)'
  934. `(eq ARITH1 ARITH2)'
  935.      These tests are true if the indicated comparison of the two
  936.      arithmetic expressions is true.  Arithmetic expressions are formed
  937.      with `plus', `minus', `mult', `div', `mod', `abs', `neg', `and',
  938.      `ior', `xor', `not', `ashift', `lshiftrt', and `ashiftrt'
  939.      expressions.
  940.  
  941.      `const_int' and `symbol_ref' are always valid terms (*note Insn
  942.      Lengths::.,for additional forms).  `symbol_ref' is a string
  943.      denoting a C expression that yields an `int' when evaluated by the
  944.      `get_attr_...' routine.  It should normally be a global variable.
  945.  
  946. `(eq_attr NAME VALUE)'
  947.      NAME is a string specifying the name of an attribute.
  948.  
  949.      VALUE is a string that is either a valid value for attribute NAME,
  950.      a comma-separated list of values, or `!' followed by a value or
  951.      list.  If VALUE does not begin with a `!', this test is true if
  952.      the value of the NAME attribute of the current insn is in the list
  953.      specified by VALUE.  If VALUE begins with a `!', this test is true
  954.      if the attribute's value is *not* in the specified list.
  955.  
  956.      For example,
  957.  
  958.           (eq_attr "type" "load,store")
  959.  
  960.      is equivalent to
  961.  
  962.           (ior (eq_attr "type" "load") (eq_attr "type" "store"))
  963.  
  964.      If NAME specifies an attribute of `alternative', it refers to the
  965.      value of the compiler variable `which_alternative' (*note Output
  966.      Statement::.) and the values must be small integers.  For example,
  967.  
  968.           (eq_attr "alternative" "2,3")
  969.  
  970.      is equivalent to
  971.  
  972.           (ior (eq (symbol_ref "which_alternative") (const_int 2))
  973.                (eq (symbol_ref "which_alternative") (const_int 3)))
  974.  
  975.      Note that, for most attributes, an `eq_attr' test is simplified in
  976.      cases where the value of the attribute being tested is known for
  977.      all insns matching a particular pattern.  This is by far the most
  978.      common case.
  979.  
  980. `(attr_flag NAME)'
  981.      The value of an `attr_flag' expression is true if the flag
  982.      specified by NAME is true for the `insn' currently being scheduled.
  983.  
  984.      NAME is a string specifying one of a fixed set of flags to test.
  985.      Test the flags `forward' and `backward' to determine the direction
  986.      of a conditional branch.  Test the flags `very_likely', `likely',
  987.      `very_unlikely', and `unlikely' to determine if a conditional
  988.      branch is expected to be taken.
  989.  
  990.      If the `very_likely' flag is true, then the `likely' flag is also
  991.      true.  Likewise for the `very_unlikely' and `unlikely' flags.
  992.  
  993.      This example describes a conditional branch delay slot which can
  994.      be nullified for forward branches that are taken (annul-true) or
  995.      for backward branches which are not taken (annul-false).
  996.  
  997.           (define_delay (eq_attr "type" "cbranch")
  998.             [(eq_attr "in_branch_delay" "true")
  999.              (and (eq_attr "in_branch_delay" "true")
  1000.                   (attr_flag "forward"))
  1001.              (and (eq_attr "in_branch_delay" "true")
  1002.                   (attr_flag "backward"))])
  1003.  
  1004.      The `forward' and `backward' flags are false if the current `insn'
  1005.      being scheduled is not a conditional branch.
  1006.  
  1007.      The `very_likely' and `likely' flags are true if the `insn' being
  1008.      scheduled is not a conditional branch.  The `very_unlikely' and
  1009.      `unlikely' flags are false if the `insn' being scheduled is not a
  1010.      conditional branch.
  1011.  
  1012.      `attr_flag' is only used during delay slot scheduling and has no
  1013.      meaning to other passes of the compiler.
  1014.  
  1015. `(attr NAME)'
  1016.      The value of another attribute is returned.  This is most useful
  1017.      for numeric attributes, as `eq_attr' and `attr_flag' produce more
  1018.      efficient code for non-numeric attributes.
  1019.  
  1020. 
  1021. File: gcc.info,  Node: Tagging Insns,  Next: Attr Example,  Prev: Expressions,  Up: Insn Attributes
  1022.  
  1023. Assigning Attribute Values to Insns
  1024. -----------------------------------
  1025.  
  1026.    The value assigned to an attribute of an insn is primarily
  1027. determined by which pattern is matched by that insn (or which
  1028. `define_peephole' generated it).  Every `define_insn' and
  1029. `define_peephole' can have an optional last argument to specify the
  1030. values of attributes for matching insns.  The value of any attribute
  1031. not specified in a particular insn is set to the default value for that
  1032. attribute, as specified in its `define_attr'.  Extensive use of default
  1033. values for attributes permits the specification of the values for only
  1034. one or two attributes in the definition of most insn patterns, as seen
  1035. in the example in the next section.
  1036.  
  1037.    The optional last argument of `define_insn' and `define_peephole' is
  1038. a vector of expressions, each of which defines the value for a single
  1039. attribute.  The most general way of assigning an attribute's value is
  1040. to use a `set' expression whose first operand is an `attr' expression
  1041. giving the name of the attribute being set.  The second operand of the
  1042. `set' is an attribute expression (*note Expressions::.) giving the
  1043. value of the attribute.
  1044.  
  1045.    When the attribute value depends on the `alternative' attribute
  1046. (i.e., which is the applicable alternative in the constraint of the
  1047. insn), the `set_attr_alternative' expression can be used.  It allows
  1048. the specification of a vector of attribute expressions, one for each
  1049. alternative.
  1050.  
  1051.    When the generality of arbitrary attribute expressions is not
  1052. required, the simpler `set_attr' expression can be used, which allows
  1053. specifying a string giving either a single attribute value or a list of
  1054. attribute values, one for each alternative.
  1055.  
  1056.    The form of each of the above specifications is shown below.  In
  1057. each case, NAME is a string specifying the attribute to be set.
  1058.  
  1059. `(set_attr NAME VALUE-STRING)'
  1060.      VALUE-STRING is either a string giving the desired attribute value,
  1061.      or a string containing a comma-separated list giving the values for
  1062.      succeeding alternatives.  The number of elements must match the
  1063.      number of alternatives in the constraint of the insn pattern.
  1064.  
  1065.      Note that it may be useful to specify `*' for some alternative, in
  1066.      which case the attribute will assume its default value for insns
  1067.      matching that alternative.
  1068.  
  1069. `(set_attr_alternative NAME [VALUE1 VALUE2 ...])'
  1070.      Depending on the alternative of the insn, the value will be one of
  1071.      the specified values.  This is a shorthand for using a `cond' with
  1072.      tests on the `alternative' attribute.
  1073.  
  1074. `(set (attr NAME) VALUE)'
  1075.      The first operand of this `set' must be the special RTL expression
  1076.      `attr', whose sole operand is a string giving the name of the
  1077.      attribute being set.  VALUE is the value of the attribute.
  1078.  
  1079.    The following shows three different ways of representing the same
  1080. attribute value specification:
  1081.  
  1082.      (set_attr "type" "load,store,arith")
  1083.      
  1084.      (set_attr_alternative "type"
  1085.                            [(const_string "load") (const_string "store")
  1086.                             (const_string "arith")])
  1087.      
  1088.      (set (attr "type")
  1089.           (cond [(eq_attr "alternative" "1") (const_string "load")
  1090.                  (eq_attr "alternative" "2") (const_string "store")]
  1091.                 (const_string "arith")))
  1092.  
  1093.    The `define_asm_attributes' expression provides a mechanism to
  1094. specify the attributes assigned to insns produced from an `asm'
  1095. statement.  It has the form:
  1096.  
  1097.      (define_asm_attributes [ATTR-SETS])
  1098.  
  1099. where ATTR-SETS is specified the same as for both the `define_insn' and
  1100. the `define_peephole' expressions.
  1101.  
  1102.    These values will typically be the "worst case" attribute values.
  1103. For example, they might indicate that the condition code will be
  1104. clobbered.
  1105.  
  1106.    A specification for a `length' attribute is handled specially.  The
  1107. way to compute the length of an `asm' insn is to multiply the length
  1108. specified in the expression `define_asm_attributes' by the number of
  1109. machine instructions specified in the `asm' statement, determined by
  1110. counting the number of semicolons and newlines in the string.
  1111. Therefore, the value of the `length' attribute specified in a
  1112. `define_asm_attributes' should be the maximum possible length of a
  1113. single machine instruction.
  1114.  
  1115. 
  1116. File: gcc.info,  Node: Attr Example,  Next: Insn Lengths,  Prev: Tagging Insns,  Up: Insn Attributes
  1117.  
  1118. Example of Attribute Specifications
  1119. -----------------------------------
  1120.  
  1121.    The judicious use of defaulting is important in the efficient use of
  1122. insn attributes.  Typically, insns are divided into "types" and an
  1123. attribute, customarily called `type', is used to represent this value.
  1124. This attribute is normally used only to define the default value for
  1125. other attributes.  An example will clarify this usage.
  1126.  
  1127.    Assume we have a RISC machine with a condition code and in which only
  1128. full-word operations are performed in registers.  Let us assume that we
  1129. can divide all insns into loads, stores, (integer) arithmetic
  1130. operations, floating point operations, and branches.
  1131.  
  1132.    Here we will concern ourselves with determining the effect of an
  1133. insn on the condition code and will limit ourselves to the following
  1134. possible effects:  The condition code can be set unpredictably
  1135. (clobbered), not be changed, be set to agree with the results of the
  1136. operation, or only changed if the item previously set into the
  1137. condition code has been modified.
  1138.  
  1139.    Here is part of a sample `md' file for such a machine:
  1140.  
  1141.      (define_attr "type" "load,store,arith,fp,branch" (const_string "arith"))
  1142.      
  1143.      (define_attr "cc" "clobber,unchanged,set,change0"
  1144.                   (cond [(eq_attr "type" "load")
  1145.                              (const_string "change0")
  1146.                          (eq_attr "type" "store,branch")
  1147.                              (const_string "unchanged")
  1148.                          (eq_attr "type" "arith")
  1149.                              (if_then_else (match_operand:SI 0 "" "")
  1150.                                            (const_string "set")
  1151.                                            (const_string "clobber"))]
  1152.                         (const_string "clobber")))
  1153.      
  1154.      (define_insn ""
  1155.        [(set (match_operand:SI 0 "general_operand" "=r,r,m")
  1156.              (match_operand:SI 1 "general_operand" "r,m,r"))]
  1157.        ""
  1158.        "@
  1159.         move %0,%1
  1160.         load %0,%1
  1161.         store %0,%1"
  1162.        [(set_attr "type" "arith,load,store")])
  1163.  
  1164.    Note that we assume in the above example that arithmetic operations
  1165. performed on quantities smaller than a machine word clobber the
  1166. condition code since they will set the condition code to a value
  1167. corresponding to the full-word result.
  1168.  
  1169.